package com.qidian.mes.qc.service.impl;/**
 * ClassName:FlawServiceImpl
 * Package:com.qidian.mes.qc.service.impl
 **/

import com.qidian.mes.pojo.Flaw;
import com.qidian.mes.qc.mapper.FlawMapper;
import com.qidian.mes.qc.service.FlawService;
import com.qidian.mes.util.dot.PagerDTO;
import com.qidian.mes.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author ppc
 * @Conpany study
 * @Description:
 * @Time 2024/4/5 14:10
 *
 **/
@Service
public class FlawServiceImpl implements FlawService {

    @Autowired
    private FlawMapper flawMapper;

    @Override
    public QdResult saveFlaws(List<Flaw> flaws) {
        return QdResult.success("成功添加"+flawMapper.insertFlaws(flaws) + "条缺陷信息");
    }

    @Override
    public QdResult<Flaw> queryById(Flaw flaw) {
        return QdResult.success(flawMapper.selectById(flaw));
    }

    @Override
    public QdResult deletes(String[] flawDescriptions) {
        flawMapper.deletes(flawDescriptions);
        return QdResult.success();
    }

    @Override
    public QdResult deleteFlaw(String flawDescription) {
        flawMapper.delete(flawDescription);
        return QdResult.success();
    }

    @Override
    public QdResult updateFlaw(Flaw flaw) {



        flawMapper.update(flaw);
        return QdResult.success();
    }

    @Override
    public QdResult saveFlaw(Flaw flaw) {
        flawMapper.insert(flaw);
       return QdResult.success();
    }

    @Override
    public QdResult<Flaw> queryByFlawDescription(String flawDescription) {
        return QdResult.success(flawMapper.selectByFlawDescription(flawDescription));
    }

    @Override
    public QdResult<PagerDTO<Flaw>> queryByPage(Flaw flaw, int page, int limit) {
        PagerDTO<Flaw> pagerDTO = new PagerDTO<>();
        pagerDTO.setPage(page);
        pagerDTO.setLimit(limit);
        pagerDTO.setTotal(flawMapper.selectCount(flaw));
        pagerDTO.setData(flawMapper.selectByPage(flaw,(page-1)*limit,limit));
        return QdResult.success(pagerDTO);

    }

    @Override
    public QdResult<List<Flaw>> queryAll() {
        return QdResult.success(flawMapper.queryAll());
    }
}
